package com.cwz.admin.service.commodity.impl;

import com.cwz.admin.entity.Commodity;
import com.cwz.admin.mapper.commodity.commodityMapper;
import com.cwz.admin.service.commodity.commodityService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class commodityServiceImpl implements commodityService {

    @Autowired
    private commodityMapper commodityMapper;
    /**
     * 商品查询 根据分类,名称,价格进行模糊查询
     *
     * @param commodity
     * @return 结果集
     */
    @Override
    public PageInfo<Commodity> adminFindCommodityByMall(Commodity commodity) {
        if(commodity.getPage()==null){
            commodity.setPage(0);
        }
        PageHelper.startPage(commodity.getPage(),6);
        List<Commodity> list = commodityMapper.adminFindCommodityByMall(commodity);
        PageInfo<Commodity> pageInf = new PageInfo<>(list);
        return pageInf;
    }

    /**
     * 商品删除 可批量删除
     *
     * @param commodityIds 删除商品id的数组
     * @return
     */
    @Override
    public int adminDelCommodityByMall(int[] commodityIds) {
        return commodityMapper.adminDelCommodityByMall(commodityIds);
    }

    /**
     * 根据商品ID查询商品信息
     *
     * @param commodityId 商品ID
     * @return
     */
    @Override
    public Commodity adminFindCommodityByID(int commodityId) {
        return commodityMapper.adminFindCommodityByID(commodityId);
    }

    /**
     * 修改商品状态
     *
     * @param Commodity 商品信息对象
     * @return
     */
    @Override
    public int adminUpdCommodity(Commodity Commodity) {
        return commodityMapper.adminUpdCommodity(Commodity);
    }
}
